﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace Zen4SyncDashboard.DAL
{
    public partial class syncSession : IDataErrorInfo
    {
        #region - IDataErrorInfo Members -

        public string Error { get { return null; } }

        public string this[string columnName]
        {
            get { return GetValidationError(columnName); }
        }

        #endregion - IDataErrorInfo Members -

        #region - Validation -

        static readonly string[] ValidatedProperties = 
        {
            "syncSession_publication",
            "syncSession_hostName",
            "syncSession_distributor",
            "syncSession_publisher",
            "syncSession_internet",
            "syncSession_exchangeType",
            "syncSession_snapshotTransferType"
        };

        public bool IsValid()
        {
            foreach (string property in ValidatedProperties)
                if (GetValidationError(property) != null)
                    return false;

            return true;
        }

        string GetValidationError(string propertyName)
        {
            if (!ValidatedProperties.Contains(propertyName))
                return null;

            string error = null;

            switch (propertyName)
            {
                case "syncSession_publication":
                    error = ValidatePublication();
                    break;
                case "syncSession_hostName":
                    error = ValidateHostName();
                    break;                
                case "syncSession_distributor":
                    error = ValidateDistributor();
                    break;
                case "syncSession_publisher":
                    error = ValidatePublisher();
                    break;
                case "syncSession_internet":
                    error = ValidateInternet();
                    break;
                case "syncSession_exchangeType":
                    error = ValidateExchangeType();
                    break;
                case "syncSession_snapshotTransferType":
                    error = ValidateSnapshotTransferType();
                    break;
                default:
                    throw new ArgumentException("Unrecognized property: " + propertyName);
            }

            return error;
        }

        private string ValidateSnapshotTransferType()
        {
            if (snapshotTransferType == null)
                return "A Snapshot Transfer Type must be selected.";

            return null;
        }

        private string ValidateExchangeType()
        {
            if (exchangeType == null)
                return "An Exchange Type must be selected.";

            return null;
        }

        private string ValidateInternet()
        {
            if (internet == null)
                return "A IIS Server must be selected.";

            return null;
        }

        private string ValidatePublisher()
        {
            if (publisher == null)
                return "A Publisher must be selected.";

            return null;
        }

        private string ValidateDistributor()
        {
            if (distributor == null)
                return "A Distributor must be selected.";

            return null;
        }

        private string ValidatePublication()
        {
            if (string.IsNullOrWhiteSpace(syncSession_hostName))
                return "Publication can't be empty.";

            return null;
        }

        private string ValidateHostName()
        {
            //if (string.IsNullOrWhiteSpace(syncSession_hostName))
            //    return "Hostname can't be empty.";

            return null;    
        }

        #endregion - Validation -
    }
}
